import React, { useState } from "react";
import "./app.css";
import Element from "./router";
import { Link } from "react-router-dom";
import * as webview from "./ulits/index";

const App = () => {

  const [code, setCode] = useState('1111111')

  const scanCode = () => {
    webview.scanCode({
      onSuccess(data) {
        setCode(data.info)
        console.log('onSuccess------->>>>>>>>>>>>>>>>', data.info)
      },
      onError(err) {
        console.log('onError------->>>>>>>>', err)
      }
    })
  }

  const navigator = () => {
    webview.navigator({
      url: '/about/print',
      onSuccess(data) {
        console.log('onSuccess------->>>>>>>>>>>>>>>>', data.info)
      },
      onError(err) {
        console.log('onError------->>>>>>>>', err)
      }
    })
  }

  
  const toAbaout = () => {
    webview.navigator({
      url: '/about',
      onSuccess(data) {
        console.log('onSuccess------->>>>>>>>>>>>>>>>', data.info)
      },
      onError(err) {
        console.log('onError------->>>>>>>>', err)
      }
    })
  }

  const blueTool = () => {
    webview.blueWire({
      onSuccess(data) {
        console.log('onSuccess------->>>>>>>>>>>>>>>>', data.info)
      },
      onError(err) {
        console.log('onError------->>>>>>>>', err)
      }
    })
  }

  return <div className="app">
    <h1>app</h1>
    <ul>
      <li><Link to="/home">Home</Link></li>
      <li><Link to="/about">About</Link></li>
    </ul>

    <div>{ code }</div>
    <div style={{ width: '60px', height: '20px' }}>
      <button onClick={scanCode} >ScanCode</button>
    </div>

    <div style={{ width: '60px', height: '20px' }}>
      <button onClick={navigator} >navigator</button>
    </div>

    <div style={{ width: '60px', height: '20px' }}>
      <button onClick={toAbaout} >toAbaout</button>
    </div>
    
    <div style={{ width: '60px', height: '20px' }}>
      <button onClick={blueTool} >打印</button>
    </div>

  </div>
};

export default App;
